package game
import (
	"message"
	"math/rand"
	"github.com/name5566/leaf/log"
)

// 机器人自动行动
func (self *Room) botAutoPlay() {
	log.Debug("botAutoPlay")
	player := self.getCurrentPlayer()
	action := self.getActionByAI(self.canCheck(player), self.canCall(player), self.canRaise(player))

	log.Debug("机器人行动:  %v  %v", player.str(), action)
	switch action {
	case message.PokerAction_ACTION_RAISE:
		// 最小加注
		self.actionRaise(player, 0)
	case message.PokerAction_ACTION_CALL:
		self.actionCall(player)
	case message.PokerAction_ACTION_CHECK:
		self.actionCheck(player)
	default:
		self.actionFold(player)
	}
}

// 测试用，机器人行动
func (self *Room) botAction(action message.PokerAction) {
	player := self.getCurrentPlayer()
	switch action {
	case message.PokerAction_ACTION_RAISE:
		// 最小加注
		self.actionRaise(player, 0)
	case message.PokerAction_ACTION_CALL:
		self.actionCall(player)
	case message.PokerAction_ACTION_CHECK:
		self.actionCheck(player)
	default:
		self.actionFold(player)
	}
}

// # 返回行动
func (self* Room)getActionByAI(canCheck bool, canCall bool, canRaise bool) message.PokerAction {
	actions := []message.PokerAction{}
	actions = append(actions, message.PokerAction_ACTION_FOLD)

	if canCheck {
		actions = append(actions, message.PokerAction_ACTION_CHECK)
	}

	if canCall {
		actions = append(actions, message.PokerAction_ACTION_CALL)
	}

	if canRaise {
		actions = append(actions, message.PokerAction_ACTION_RAISE)
	}

	index := rand.Intn(len(actions))
	return actions[index]
}
